var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function s() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (s.prototype = e.prototype, 
    new s());
}), a = this && this.__decorate || function(t, e, o, s) {
    var n, a = arguments.length, i = a < 3 ? e : null === s ? s = Object.getOwnPropertyDescriptor(e, o) : s;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(t, e, o, s); else for (var c = t.length - 1; 0 <= c; c--) (n = t[c]) && (i = (a < 3 ? n(i) : 3 < a ? n(e, o, i) : n(e, o)) || i);
    return 3 < a && i && Object.defineProperty(e, o, i), i;
};

Object.defineProperty(n, "__esModule", {
    value: !0
}), n.NewActivityEggType = void 0;

var r, s = e("GameData"), c = e("DataManager"), l = e("EggsManager"), d = e("LoadManager"), u = e("UIManager"), p = e("WebManager"), h = e("Global"), f = cc._decorator, g = f.ccclass;

f.property, function(t) {
    t[t.CLICK = 0] = "CLICK", t[t.DEALY = 1] = "DEALY", t[t.MOVE = 2] = "MOVE", t[t.COMPLEX = 3] = "COMPLEX";
}(r = n.NewActivityEggType || (n.NewActivityEggType = {}));

var m = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.data = {
            id: 21,
            type: r.CLICK,
            num: 1,
            options: {}
        }, t.count = 0, t.btnNode = null, t.isExe = !1, t;
    }
    return i(t, e), t.prototype.start = function() {}, t.prototype.init = function(t) {
        (this.data = t).options.pos && this.node.setPosition(t.options.pos), t.options.size && this.node.setContentSize(t.options.size), 
        t.options.personIdx && cc.systemEvent.on("refresh_person_skin", this.refreshCallback, this), 
        GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) && !s.GD.isFollow && this.node.on("follow_success", this.doReward, this), 
        this.addEvent();
    }, t.prototype.addEvent = function() {
        switch (this.data.type) {
          case r.CLICK:
            this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
            break;

          case r.DEALY:
            this.node.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
            this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
            break;

          case r.MOVE:
            this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
            break;

          case r.COMPLEX:
            this.node.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), 
            this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this), 
            this.data.options.target && (this.btnNode = new cc.Node(), d.default.getInstance().loadSpriteFrame({
                url: this.data.options.path,
                sprite: this.btnNode.addComponent(cc.Sprite)
            }), this.btnNode.zIndex = -1, this.data.options.scale && (this.btnNode.scale = this.data.options.scale), 
            this.btnNode.setPosition(this.data.options.pos), this.btnNode.parent = this.data.options.target.parent);
        }
    }, t.prototype.removeEvent = function() {
        switch (this.node.off("follow_success", this.doReward, this), this.data.options.personIdx && cc.systemEvent.off("refresh_person_skin", this.refreshCallback, this), 
        this.data.type) {
          case r.CLICK:
            this.node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
            break;

          case r.DEALY:
            this.node.off(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), this.node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
            this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
            break;

          case r.MOVE:
            this.node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
            break;

          case r.COMPLEX:
            this.node.off(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), this.node.off(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), 
            this.node.off(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), this.node.off(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
        }
    }, t.prototype.touchStartHandler = function(t) {
        switch (this.data.type) {
          case r.CLICK:
            break;

          case r.DEALY:
            this.scheduleOnce(this.callback, this.data.num);
            break;

          case r.MOVE:
            break;

          case r.COMPLEX:
            var e;
            this.data.options.target && (e = t.getLocation(), e = this.data.options.target.convertToNodeSpaceAR(e), 
            Math.abs(e.x) <= this.data.options.target.width / 2 && Math.abs(e.y) <= this.data.options.target.height / 2 && this.scheduleOnce(this.delayCallback, this.data.num));
        }
    }, t.prototype.touchMoveHandler = function(t) {
        switch (this.data.type) {
          case r.CLICK:
            break;

          case r.MOVE:
            50 < t.getPreviousLocation().sub(t.getLocation()).mag() && (this.count < this.data.num && this.count++, 
            this.count == this.data.num && this.callback());
            break;

          case r.COMPLEX:
            0 < this.count && this.data.options.target && this.data.options.target.setPosition(this.data.options.target.parent.convertToNodeSpaceAR(t.getLocation()));
        }
    }, t.prototype.touchEndHandler = function(t) {
        switch (this.data.type) {
          case r.CLICK:
            this.count < this.data.num && this.count++, this.count == this.data.num && this.callback();
            break;

          case r.DEALY:
            this.unschedule(this.callback);
            break;

          case r.MOVE:
            break;

          case r.COMPLEX:
            var e;
            this.data.options.target && (this.unschedule(this.delayCallback), 1 == this.count ? this.count = 0 : (e = t.getLocation(), 
            e = this.btnNode.convertToNodeSpaceAR(e), Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (e = this.data.options.scale || 1, 
            cc.tween(this.btnNode).to(.1, {
                scale: 1.1 * e
            }).to(.1, {
                scale: +e
            }).start(), this.callback(), this.data.options.target.setPosition(this.data.options.pos), 
            this.btnNode.destroy(), this.btnNode = null)));
        }
    }, t.prototype.refreshCallback = function() {
        this.data.options.personView && this.data.options.personView.personIdx == this.data.options.personIdx && -1 == l.default.getInstance().checkEggPerson(this.data.id) ? this.node.active = !0 : this.node.active = !1;
    }, t.prototype.delayCallback = function() {
        this.count = 1;
    }, t.prototype.callback = function() {
        var e = this;
        this.isExe || (this.isExe = !0, -1 != l.default.getInstance().checkEggPerson(this.data.id)) || (!GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) || s.GD.isFollow ? this.doReward() : u.default.getInstance().loadPnl("eggsTips").then(function(t) {
            t && (t.target = e.node), e.isExe = !1;
        }));
    }, t.prototype.doReward = function() {
        var t = this;
        p.default.getInstance().sentLog("获得皮肤彩蛋id:" + this.data.id), this.node.on("egg_get", this.doGet, this), 
        u.default.getInstance().loadPopPnl("egg_get", {
            type: h.RewardType.SKIN,
            idx: this.data.id,
            target: this.node,
            success: function() {
                t.isExe = !1;
            }
        });
    }, t.prototype.doGet = function() {
        this.removeEvent(), l.default.getInstance().updateEggPerson(this.data.id), s.GD.personIdx = -1 - this.data.id, 
        s.GD.eggsHintState = 1, c.default.getInstance().save(), this.node.off("egg_get"), 
        u.default.getInstance().hideAllPnl(), u.default.getInstance().showPnl("start");
    }, a([ g ], t);
}(cc.Component);

n.default = m;